import { request } from '@umijs/max';
import { setAuthHeader } from '@/utils/authInterceptor';

/**
 * 分页查询登录日志
 * @param params 查询参数
 * @returns 登录日志列表数据
 */
export async function getLoginLogListPaginated(params: OPERATION_LOG.LoginLogListParams) {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  };
  
  // 添加认证头
  setAuthHeader(headers);
  
  return request<OPERATION_LOG.LoginLogListResponse>('/api/logs/login/page', {
    method: 'POST',
    headers,
    data: params,
  });
}

/**
 * 获取登录统计数据
 * @param startTime 开始时间
 * @param endTime 结束时间
 * @returns 登录统计数据
 */
export async function getLoginStats(startTime?: string, endTime?: string) {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  };
  
  // 添加认证头
  setAuthHeader(headers);
  
  return request<OPERATION_LOG.LoginStatsResponse>('/api/logs/login/stats', {
    method: 'GET',
    headers,
    params: {
      startTime,
      endTime,
    },
  });
}

/**
 * 获取每日登录次数
 * @param startTime 开始时间
 * @param endTime 结束时间
 * @returns 每日登录次数数据
 */
export async function getDailyLoginCounts(startTime?: string, endTime?: string) {
  const headers: Record<string, string> = {
    'Content-Type': 'application/json',
  };
  
  // 添加认证头
  setAuthHeader(headers);
  
  return request<OPERATION_LOG.DailyLoginCountResponse>('/api/logs/login/daily-counts', {
    method: 'GET',
    headers,
    params: {
      startTime,
      endTime,
    },
  });
}